Код:
	
/*:
 *-----------------------------------------------------------------------------
 *  DKR PrimitiveButton
 *-----------------------------------------------------------------------------
 *  For: RPGMAKER MV
 *  DKR_PrimitiveButton_3.js
 *-----------------------------------------------------------------------------
 *  19.03.2022 - Версия 3.0.0
 *  19.08.2021 - Версия 2.0.0
 *  18.08.2021 - Версия 1.0.0
 *-----------------------------------------------------------------------------
 * Поставляется AS-IS.
 * Вся ответственность при использовании - на Пользователе!
 *-----------------------------------------------------------------------------
 *-----------------------------------------------------------------------------
 * @author Yoji Ojima, DarchanKaen
 * @target MV
 * @plugindesc (v.3.0.0) Плагин позволяет отображать на экране кнопку в виде картинки / текста / 
 * текста на фоне картинки, вызывать Общее событии при ЛКМ на ней (и кое-что еще).
 * @help
 *   DKR PrimitiveButton_3
 * ----------------------------------------------------------------------------
 * ---Общая информация:
 * Плагин позволяет отображать на экране кнопку в виде картинки / текста / текста на фоне картинки, 
 * вызывать Общее событии при клике ЛКМ на ней, и трекать наведение мышки на картинку ("hover").
 *
 * Трекинг работает в экспериментальном режиме и, теоретически, может снижать FPS на 1-5 пунктов(!).
 *
 * На кнопку действуют все стандартные команды картинок. 
 * Удаляется кнопка командой мейкера "Удалить картинку" по ее номеру; при использовании команды ... displayTextButtonWithBackgorund...
 * нужно удалять номер картинки(фон) и номер картинки + 1 (сама кнопка).
 *
 * --Команды (для раздела "Скрипт"):
 * DKR.PrimitiveButton.displayTextButton(buttonText, pictureId, pictureX, pictureY, commonEventId); 
 * - выводит "текстовую" кнопку.
 *
 * DKR.PrimitiveButton.displayImageButton(pictureName, pictureId, pictureX, pictureY, commonEventId);
 * - выводит кнопку-картинку.
 *
 * DKR.PrimitiveButton.displayTextButtonWithBackgorund(buttonText, pictureName, pictureId, pictureX, pictureY, pictureXOffset, pictureYOffset, commonEventId);
 * - выводит "текстовую" кнопку на фоне картинки.
 *
 * DKR.PrimitiveButton.hoverTrackingOnOff(isTrackingOn) - включить / выключение трекинга.
 *
 * где:
 * buttonText - текст, допускающий контрольные символы (ставьте \\ вместо \);
 * pictureName - название файла картинки в папке \img\pictures БЕЗ .png;
 * pictureId - номер картинки;
 * pictureX, pictureY - координаты X и Y картинки;
 * pictureXOffset, pictureYOffset - промежутки между левым и верхним краем картинки и краями "текстовой" кнопки (для красоты);
 * commonEventId - номер Общего события;
 * isTrackingOn - включить (true) / выключить (false) трекинг на картинку / кнопку.
 *
 * ----------------------------------------------------------------------------
 * @param idOfClickedPictureVarId
 * @type variable
 * @desc Номер переменной для хранения номера (id)картинки / кнопки, по которой сделан клик
 * @default 4
 *
 * @param hoverTrackingIsOn
 * @type boolean
 * @desc Включен ли трекинг факта наведения на кнопку или картинку (теоретически может уменьшать FPS!).
 * @default false
 * 
 * @param hoverTrackingIsHoverSwitchId
 * @type switch
 * @desc Номер переключателя для хранения факта наведения на картинку / кнопку.
 * @default 5
 *
 * @param hoverTrackingPictureIdVarId
 * @type variable
 * @desc Номер переменной для хранения номера (id)картинки / кнопки, на которой наведение.
 * @default 5
 *
 */
var Imported = Imported || {};
Imported.DKR_PrimitiveButton = true;
var DKR = DKR || {};          
DKR.PrimitiveButton = DKR.PrimitiveButton || {}; 
DKR.PrimitiveButton.version = 3.0;
DKR.PrimitiveButton.parameters = PluginManager.parameters('DKR_PrimitiveButton_3');
(() => {
	
	
	
//--------DATA: BEGIN	
	DKR.PrimitiveButton.idOfClickedPictureVarId = Number(DKR.PrimitiveButton.parameters['idOfClickedPictureVarId']) || 4;
	DKR.PrimitiveButton.hoverTrackingIsOn = (DKR.PrimitiveButton.parameters['hoverTrackingIsOn']=== 'true') ? true : false;
	DKR.PrimitiveButton.hoverTrackingIsHoverSwitchId = Number(DKR.PrimitiveButton.parameters['hoverTrackingIsHoverSwitchId']) || 5;
	DKR.PrimitiveButton.hoverTrackingPictureIdVarId = Number(DKR.PrimitiveButton.parameters['hoverTrackingPictureIdVarId']) || 5;
	const pictureOrigin = 0;
	const pictureScaleX = 100;
	const pictureScaleY = 100;
	const pictureOpacity = 255;
	const pictureBlendMode = 0;	
//--------DATA: END	
//--------WINDOW BASE BLOCK: BEGIN
Window_Base.prototype.textSizeEx = function(text) {
    this.resetFontSettings();
	
    var textState = { index: 0, x: 0, y: 0, left: 0 };
    textState.text = this.convertEscapeCharacters(text);
    textState.height = this.calcTextHeight(textState, false);
    textState.drawing = false;
	
	let tWidth = this.textWidth(text);
	let hHeight = this.calcTextHeight(textState, false);
	let wCoeff = 1.25;
	if(tWidth < 90){
		wCoeff = 2;
	}else if(tWidth < 130){
		wCoeff = 1.45;
	}
	tWidth = Math.ceil( tWidth * wCoeff );
	hHeight = Math.ceil( hHeight * 2 );
	return { width: tWidth, height: hHeight };
};
//--------WINDOW BASE BLOCK: BEGIN
//--------TOUCH INPUT BLOCK: BEGIN
TouchInput.isHovered = function() {
    return this.__hovered;
};
//--------TOUCH INPUT BLOCK: END
	
	
//--------TEXT PICTURE BLOCK: BEGIN
	let textPictureText = "";
    const _Game_Picture_show = Game_Picture.prototype.show;
    Game_Picture.prototype.show = function() {
        _Game_Picture_show.apply(this, arguments);
        if (this._name === "" && textPictureText) {
            this.mzkp_text = textPictureText;
            this.mzkp_textChanged = true;
            textPictureText = "";
        }
    };
    const _Sprite_Picture_destroy = Sprite_Picture.prototype.destroy;
    Sprite_Picture.prototype.destroy = function() {
        destroyTextPictureBitmap(this.bitmap);
        _Sprite_Picture_destroy.apply(this, arguments);
    };
    const _Sprite_Picture_updateBitmap = Sprite_Picture.prototype.updateBitmap;
    Sprite_Picture.prototype.updateBitmap = function() {
        _Sprite_Picture_updateBitmap.apply(this, arguments);
        if (this.visible && this._pictureName === "") {
            const picture = this.picture();
            const text = picture ? picture.mzkp_text || "" : "";
            const textChanged = picture && picture.mzkp_textChanged;
            if (this.mzkp_text !== text || textChanged) {
                this.mzkp_text = text;
                destroyTextPictureBitmap(this.bitmap);
                this.bitmap = createTextPictureBitmap(text);
                picture.mzkp_textChanged = false;
            }
        } else {
            this.mzkp_text = "";
        }
    };
    function createTextPictureBitmap(text) {
        const tempWindow = new Window_Base(new Rectangle());
        const size = tempWindow.textSizeEx(text);
		tempWindow.padding = 0;
        tempWindow.move(0, 0, size.width, size.height);
        tempWindow.createContents();
        tempWindow.drawTextEx(text, 0, 0, 0);
        const bitmap = tempWindow.contents;
        tempWindow.contents = null;
        tempWindow.destroy();
        bitmap.mzkp_isTextPicture = true;
        return bitmap;
    }
    function destroyTextPictureBitmap(bitmap) {
        if (bitmap && bitmap.mzkp_isTextPicture) {
            bitmap.clear();
        }
    }
	
	
	const displayTextPicture = function(pictureText){
		textPictureText = String(pictureText);
	}
//--------TEXT PICTURE BLOCK: END
	
	
	
//--------BUTTON PICTURE BLOCK: BEGIN
	
	//----CHANGE PICTURE SPRITE AS MZ CLICKABLE SPRITE
	
	Sprite_Picture.prototype.initialize = function(pictureId) {
		Sprite.prototype.initialize.call(this);
		this._pictureId = pictureId;
		this._pictureName = '';
		this._isPicture = true;
		this._pressed = false;
		this._hovered = false;
		this.update();
	};
		
	
	Sprite_Picture.prototype.isClickEnabled = function() {
		return this.worldVisible;
	};
		
		
	Sprite_Picture.prototype.processTouch = function() {
		if (this.isClickEnabled()) {
			if (this.isBeingTouched()) {
					if(true === DKR.PrimitiveButton.hoverTrackingIsOn){
						$gameSwitches.setValue(DKR.PrimitiveButton.hoverTrackingIsHoverSwitchId, true);
						$gameVariables.setValue(DKR.PrimitiveButton.hoverTrackingPictureIdVarId, this._pictureId);
					}
				if (!this._hovered && TouchInput.isHovered()) {
					this._hovered = true;
					this.onMouseEnter();
				}
				if (TouchInput.isTriggered()) {
					this._pressed = true;
					this.onPress();
				}
			} else {
				if(true === DKR.PrimitiveButton.hoverTrackingIsOn){
						$gameSwitches.setValue(DKR.PrimitiveButton.hoverTrackingIsHoverSwitchId, false);
						$gameVariables.setValue(DKR.PrimitiveButton.hoverTrackingPictureIdVarId, -1);
				}
				if (this._hovered) {
					this.onMouseExit();
				}
				this._pressed = false;
				this._hovered = false;
			}
			if (this._pressed && TouchInput.isReleased()) {
				this._pressed = false;
				this.onClick();
			}
		} else {
			this._pressed = false;
			this._hovered = false;
		}
		
	};
		
	
	Sprite_Picture.prototype.isPressed = function() {
		return this._pressed;
	};
	Sprite_Picture.prototype.isClickEnabled = function() {
		const picture = this.picture();
		return picture && picture.mzkp_commonEventId && !$gameMessage.isBusy();
	};
	Sprite_Picture.prototype.isBeingTouched = function() {
		const touchPos = new Point(TouchInput.x, TouchInput.y);
		const localPos = this.worldTransform.applyInverse(touchPos);
		return this.hitTest(localPos.x, localPos.y);
	};
	Sprite_Picture.prototype.hitTest = function(x, y) {
		const rect = new Rectangle(
			-this.anchor.x * this.width,
			-this.anchor.y * this.height,
			this.width,
			this.height
		);
		return rect.contains(x, y);
	};
	
	
	Sprite_Picture.prototype.onMouseEnter = function() {
		//
	};
	Sprite_Picture.prototype.onMouseExit = function() {
		//
	};
	Sprite_Picture.prototype.onPress = function() {
		//
	};
	Sprite_Picture.prototype.onClick = function() {
		//- basic MZ: NONE
		if( this.picture().mzkp_commonEventId > 0){
			$gameVariables.setValue(DKR.PrimitiveButton.idOfClickedPictureVarId, this._pictureId);
			$gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
		}
		
	};	
		
	
	DKR.PrimitiveButton.__update = Sprite_Picture.prototype.update;
	Sprite_Picture.prototype.update = function(){
		DKR.PrimitiveButton.__update.call(this);
		this.processTouch();
	}
	//-
	
	
	
	//----BUTTON PICTURE LOGIC
	Spriteset_Base.prototype.mzkp_isAnyPicturePressed = function() {
        return this._pictureContainer.children.some(sprite =>
            sprite.isPressed()
        );
    };
	
	
	const _Scene_Map_isAnyButtonPressed = Scene_Map.prototype.isAnyButtonPressed;
	
	
    Scene_Map.prototype.isAnyButtonPressed = function() {
        return (
            _Scene_Map_isAnyButtonPressed.apply(this, arguments) ||
            this._spriteset.mzkp_isAnyPicturePressed()
        );
    };
	
	
	const displayButtonPicture = function(picId, cEId){
		const pictureId = picId;
		const commonEventId = cEId;
		const picture = $gameScreen.picture(pictureId);
		if (picture){
			picture.mzkp_commonEventId = commonEventId;
		}
	}
	//-
//--------BUTTON PICTURE BLOCK: END
//--------DISPLAY PICTURE BLOCK: BEGIN	
	const displayPrimitiveButton = function(isTextButtonMode, buttonText, pictureId, pictureName, pictureX, pictureY, commonEventId){
		if(true === isTextButtonMode){
			$gameScreen.showPicture(pictureId, '', pictureOrigin, pictureX, pictureY, pictureScaleX, pictureScaleY, pictureOpacity, pictureBlendMode);
			displayTextPicture(buttonText);
		}else{
			$gameScreen.showPicture(pictureId, pictureName, pictureOrigin, pictureX, pictureY, pictureScaleX, pictureScaleY, pictureOpacity, pictureBlendMode);
		}
		displayButtonPicture(pictureId, commonEventId);
		
			//-second, becouse some strange bug 
		if(true === isTextButtonMode){
			$gameScreen.showPicture(pictureId, '', pictureOrigin, pictureX, pictureY, pictureScaleX, pictureScaleY, pictureOpacity, pictureBlendMode);
			displayTextPicture(buttonText);
		}else{
			$gameScreen.showPicture(pictureId, pictureName, pictureOrigin, pictureX, pictureY, pictureScaleX, pictureScaleY, pictureOpacity, pictureBlendMode);
		}
		displayButtonPicture(pictureId, commonEventId);
	}
//--------DISPLAY PICTURE BLOCK: END	
	
	
//--------COMMANDS: BEGIN
	DKR.PrimitiveButton.displayTextButton = function(buttonText, pictureId, pictureX, pictureY, commonEventId){
		displayPrimitiveButton(true, buttonText, pictureId, '', pictureX, pictureY, commonEventId);
	}
	
	DKR.PrimitiveButton.displayImageButton = function(pictureName, pictureId, pictureX, pictureY, commonEventId){
		displayPrimitiveButton(false, '', pictureId, pictureName, pictureX, pictureY, commonEventId);
	}
	
	DKR.PrimitiveButton.displayTextButtonWithBackgorund = function(buttonText, pictureName, pictureId, pictureX, pictureY, pictureXOffset, pictureYOffset, commonEventId){
		$gameScreen.showPicture(pictureId, pictureName, pictureOrigin, pictureX, pictureY, pictureScaleX, pictureScaleY, pictureOpacity, pictureBlendMode);
		displayPrimitiveButton(true, buttonText, pictureId + 1, '', (pictureX + pictureXOffset), (pictureY + pictureYOffset), commonEventId);
	}
	
	DKR.PrimitiveButton.hoverTrackingOnOff = function(isTrackingOn){
		DKR.PrimitiveButton.hoverTrackingIsOn = isTrackingOn;
	}
//--------COMMANDS: END
	
})();
	
})();
 
Социальные закладки